package 锁;

//wait和notify不是同一个对象
public class Demo_7 {
    static Object A = new Object();
    static Object B = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                try {
                    System.out.println("准备进入wait状态，等待notify唤醒");
                    A.wait();
                    System.out.println("被唤醒");
                } catch (InterruptedException e) {
                    System.out.println("被interrupt唤醒");
                }
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (B) {
                try {
                    //确保t1进入wait状态
                    Thread.sleep(1000);
                    System.out.println("准备唤醒A锁");
                    B.notify();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t1.start();
        t2.start();
    }
}
